package com.example.ssmDemo.core.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

/**
 * 模块名称：
 * 模块类型：
 * 编码人：刘彬
 * 生成时间：2023/2/23
 * 联系电话：
 * */
@Controller
public class PageController {
    @RequestMapping(value = "/")
    public  String LoginPage(){
        System.out.println("显示登录页面");
        return "/core/login";
    }
    @RequestMapping("/user/toMain")
    public String toMainPage(){
        System.out.println("去到首页");
        return "/student/main";
    }
    @RequestMapping("/outLogin")
    public String outLogin(HttpSession session,HttpServletRequest request){
        ServletContext servletContext = request.getSession().getServletContext();
        HashMap<String,String>loginMap= (HashMap<String, String>) servletContext.getAttribute("loginMap");
        String userName= (String) session.getAttribute("userName");
        loginMap.remove(userName);
        servletContext.removeAttribute("loginMap");
        servletContext.setAttribute("loginMap",loginMap);
        session.invalidate();
        return "redirect:/";
    }

}
